<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="出入口名称">

          <a-select    v-decorator="['armName', {rules: [{required: true, message: '请选择设备!' }]}]"  placeholder="请选择设备"  @change="one" :disabled=isDisabled>

            <a-select-option v-for="parkArmInfos in parkArmInfo" :key="parkArmInfos.serialNo">
              {{ parkArmInfos.armName }}
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="第一行">
          <a-input placeholder="请输入第一行" v-decorator="['firstLine', {rules: [{required: true, message: '请输入第一行!' }]}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="第二行">
          <a-input placeholder="请输入第二行" v-decorator="['secondLine', {rules: [{required: true, message: '请输入第二行!' }]}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="第三行">
          <a-input placeholder="请输入第三行" v-decorator="['thirdLine', {rules: [{required: true, message: '请输入第三行!' }]}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="第四行">
          <a-input placeholder="请输入第四行" v-decorator="['fourthLine', {rules: [{required: true, message: '请输入第四行!' }]}]" />
        </a-form-item>
 <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="音量">
      <a-input-number :min="1" :max="10" v-decorator="['volume', {initialValue:6}]" />        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { httpAction,getAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "LedAdvertisingManagementModal",
    data () {
      return {
         parkArmInfo:[],
        parkArmInfos:[],
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        isDisabled:[],
        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        },
        url: {
          add: "/ledadvertisingmanagement/ledAdvertisingManagement/add",
          edit: "/ledadvertisingmanagement/ledAdvertisingManagement/edit",
        },
      }
    },
    created () {
        this.getparkArmInfo()
    },
    methods: {
      one(serialNo) {
      this.model.serialNo=serialNo;
    },
      getparkArmInfo(){
      getAction("/parking/parkArmInfo/getParkArmList").then((res)=>{
              if(res.success){
              this.parkArmInfo=res.result;
              }
            })

      },
      add () {

        this.edit({});
      },
      edit (record) {
       if(record.id==undefined){

         this. isDisabled=false;
       }else{
         this. isDisabled=true;
       }
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'parkCode','parkName','volume','armName','ipAddr','serialNo','firstLine','secondLine','thirdLine','fourthLine','createUser'))
		  //时间格式化

        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化

            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>
